export function getRankChartOption(data: any) {
  // const data = [
  //   {
  //     name: '白马工交',
  //     value: 1260
  //   },
  //   {
  //     name: '超大公交',
  //     value: 927
  //   },
  //   {
  //     name: '中巴公交',
  //     value: 859
  //   },
  //   {
  //     name: '德运公交',
  //     value: 765
  //   },
  //   {
  //     name: '程德新公交',
  //     value: 478
  //   }
  // ]
  const getArrByKey = (data: any, k: any) => {
    const key = k || 'value'
    const res: any = []
    if (data) {
      data.forEach(function(t: any) {
        res.push(t[key])
      })
    }
    return res // ["桂林", "柳州", "北海", "防城巷", "百色"]
  }
  const getSymbolData = (data: any) => {
    const arr = []
    for (let i = 0; i < data.length; i++) {
      arr.push({
        value: data[i].value,
        symbolPosition: 'end'
      })
    }
    return arr // [{value:10,symbolPosition:'end'}]
  }
  // console.log(getSymbolData(data));
  return {
    grid: {
      top: '2%',
      bottom: 5,
      right: 24,
      left: -50,
      containLabel: true
    },
    xAxis: {
      show: false
    },
    yAxis: [
      {
        triggerEvent: true,
        show: true,
        inverse: true,
        data: getArrByKey(data, 'name'),
        axisLine: {
          show: false
        },
        splitLine: {
          show: false
        },
        axisTick: {
          show: false
        },

        axisLabel: {
          show: true,
          interval: 0,
          color: '#fff',
          align: 'left',
          margin: 100,
          formatter: function(value: any) {
            return '{title|' + value + '}'
          },
          rich: {
            title: {
              width: 50,
              align: 'left',
              fontSize: 18,
              fontFamily: 'PingFang Regular'
            }
          }
        }
      },
      {
        triggerEvent: true,
        show: true,
        inverse: true,
        data: getArrByKey(data, 'name'),
        axisLine: {
          show: false
        },
        splitLine: {
          show: false
        },
        axisTick: {
          show: false
        },
        axisLabel: {
          interval: 0,
          shadowOffsetX: '-20px',
          color: ['#fff'],
          align: 'left',
          verticalAlign: 'center',
          lineHeight: 40,
          fontSize: 20,
          margin: 25,
          formatter: function(value: any, index: number) {
            return data[index].value
          }
        }
      }
    ],
    series: [
      {
        name: '', // 发光的⭕️
        type: 'pictorialBar',
        symbol:
          // '',
          'image://',
        symbolSize: [40, 40],
        symbolOffset: [20, 0],
        z: 12,
        itemStyle: {
          normal: {
            color: '#fff'
          }
        },
        data: getSymbolData(data)
      },
      {
        name: '条',
        type: 'bar',
        showBackground: true,
        // barBorderRadius: 30,
        yAxisIndex: 0,
        data: data,
        barWidth: 5,
        // align: left,
        itemStyle: {
          normal: {
            // color: 'rgba(41, 162, 245, 1)',
            color: '#0096FF',
            barBorderRadius: 5
          }
        },
        backgroundStyle: {
          color: '#203AA4'
        }
      }
    ]
  }
}
